import corejuliano.designpattern.mvc.*;
import corejuliano.gameelement.*;
import corejuliano.*;
import flash.geom.*;
import util.*;


class corejuliano.gameelement.Tileable extends Controller
{
	private var solid:Boolean;
	
	public function Tileable(id:String)
	{
		super(id);		
	}
	
	public function createModel(id:String):Void
	{
		model = new TileableModel(id);	
	}
	
	public function isSolid():Boolean
	{
		return solid;
	}		

	public function getTile():Tile
	{
		return TileableModel(model).getTile();
	}

	public function setTile(tile:Tile):Void
	{
		if (TileableModel(model).getTile())
			TileableModel(model).getTile().removeTileable(this);
			
		TileableModel(model).setTile(tile);
		TileableModel(model).getTile().addTileable(this);
		var spacing:Number = GameManager.getInstance().getActivePhase().getWorld().getSpacing();
		var position:Point = new Point(tile.getPosition().x * spacing, tile.getPosition().y * spacing);
		TileableModel(model).setPosition(position);
		tile.setArea(new Rectangle(tile.getPosition().x, tile.getPosition().y, spacing, spacing));
	}
		
	public function setSolid(solid:Boolean):Void 
	{
		this.solid = solid;
	}
	
	public function destroy():Void
	{		
		TileableModel(model).getTile().removeTileable(this);
		TileableModel(model).destroy();
		super.destroy();
	}
	
	public function toString(Void):String 
	{
		return "corejuliano.gameelement.Tileable";
	}

}